<template>
    <div>
<van-nav-bar title="注册" />
<van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="username"
      name="用户名"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password"
      :type="eye!=eye?'text':'password'"
      name="密码"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    >
<template #button>
    <van-icon name="eye-o"  size="25px" v-if="eye"/>
</template>
</van-field>
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      提交
    </van-button>
  </div>
</van-form>

    </div>
</template>

<script setup>
import { ref } from 'vue';
import { showToast } from 'vant';
import { loginApi } from "@/api/api";
import router from '@/router';
 const username = ref('');
    const password = ref('');
    const onSubmit = () => {
      loginApi(username.value,password.value).then(res=>{
        console.log('login',res);
        localStorage.setItem('token',res.data.data.token)
        localStorage.setItem('username',username.value)
        if(res.data.code==0){
         showToast({
            type:"success",
            message:'登录成功',
            duration:1500,
            onClose(){
                router.push('/')
            }
         });

        }
      })
    };
    let eye=ref(true)
</script>

<style lang="scss" scoped>

</style>